package com.example.pruebaHttp;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.view.ViewGroup.LayoutParams;
import android.widget.Spinner;
import android.view.Display;
@SuppressLint("DefaultLocale")
public class MainActivity extends Activity {
	
	private Spinner spinner1;
	private List<String> lista;
	private String region = "NA";
	@SuppressWarnings("deprecation")
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.activity_main);
		//Escalado
		ImageView logo = (ImageView) findViewById(R.id.lslogo);
		LayoutParams params = logo.getLayoutParams();
		Display display = getWindowManager().getDefaultDisplay();
		params.width = display.getWidth();
		params.height = (int) (0.39*display.getWidth());
		logo.setLayoutParams(params);
		//FinEscalado
		iniciarListaRegiones();
		final EditText edttxt = (EditText) findViewById (R.id.editText1);
		      String nuevoDato = edttxt.getText().toString();
		      nuevoDato=nuevoDato.trim();
	}
	
	
	//Iniciar la lista de las Regiones.
	private void iniciarListaRegiones() {
		   spinner1 = (Spinner) findViewById(R.id.spinner1);
		   lista = new ArrayList<String>();
		   spinner1 = (Spinner) this.findViewById(R.id.spinner1);
		   lista.add("NA");
		   lista.add("EUW");
		   lista.add("EUNE");
		   lista.add("BR");
		   lista.add("LAN");
		   lista.add("LAS");
		   lista.add("OCE");
		   ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lista);
		   adaptador.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		   spinner1.setAdapter(adaptador);
		   spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
			   @Override
			   public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			      //Toast.makeText(arg0.getContext(), "Seleccionado: " + arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_SHORT).show();
			      region = arg0.getItemAtPosition(arg2).toString().toLowerCase();
			   }
			   @Override
			   public void onNothingSelected(AdapterView<?> arg0) {
			   }
			});
		}
	//Pasamos y ejecutamos la Actividad principal de la aplicacion.
	public void ejecutar(View view) {
		Intent i = new Intent(this, LoadingScreen.class);
		Bundle b = new Bundle();
		final EditText edttxt = (EditText) findViewById (R.id.editText1);
	      String nuevoDato = edttxt.getText().toString().toLowerCase();
	      nuevoDato=nuevoDato.trim();
	      nuevoDato = nuevoDato.replaceAll("\\s", "");
	      b.putString("name", nuevoDato);
		b.putString("region", region);
		i.putExtras(b);
		System.out.println("Nombre: "+nuevoDato);
		startActivity(i);
	}
}